<!DOCTYPE html>
<#assign f = JspTaglibs["http://www.casic304.cn/f"] />
<html>
<head>
    <meta charset="utf-8">
    <title>质量知识信息列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
    <style>

        .qbdms-noData{
            position: absolute;left: 50%;top:40%;transform:translate(-50%,-40%);
            display: none;
            text-align: center;
            z-index: 1111;
        }
        .qbdms-noData div{
            margin-top: 10px;
        }
        /*滚动条样式*/
        .qbdms-list-content .right-list::-webkit-scrollbar {
            width: 4px;
            /*height: 4px;*/
        }
        .qbdms-list-content .right-list::-webkit-scrollbar-thumb {
            border-radius: 10px;
            /*-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);*/
            background: #c1c5cd;
        }
        .qbdms-list-content .right-list::-webkit-scrollbar-track {
            /*-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);*/
            border-radius: 0;
            background: #f5f5f5;

        }
        #list .layui-icon-star-fill{
            color: #2682ff;
        }
        #list .layui-icon.iconcollection{
            cursor: pointer;
            margin-left: 16px;
        }
        #list span.collections{
            margin-left: 0;
        }
        .rightCon .fillBtn{
            float: left;
            margin-right: 8px;
        }
        .caller-main>p{
            width: 100%;
            /*white-space: nowrap;*/
            overflow: hidden;
            text-overflow: ellipsis;
        }
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        body{font:12px/180% Arial, Helvetica, sans-serif, "新宋体";}
        /* select */
        .select{border: #ddd 1px solid;border-radius: 4px;margin: 2% auto;font-size: 12px;}
        .select li{list-style:none;padding:10px 0 5px 100px}
        .select .select-list{border-bottom:#eee 1px dashed}
        .select dl{zoom:1;position:relative;line-height:24px;}
        .select dl:after{content:" ";display:block;clear:both;height:0;overflow:hidden}
        .select dt{width:100px;margin-bottom:5px;position:absolute;top:0;left:-100px;text-align:right;color:#666;height:24px;line-height:24px}
        .select dd{float:left;display:inline;margin:0 0 5px 5px;}
        .select a{display:inline-block;white-space:nowrap;height:24px;padding:0 10px;text-decoration:none;color:#039;border-radius:2px;}
        .select a:hover{color:#000;background-color:#f3edc2}
        .select .selected a{color:#fff;background-color:#2682FF;}
        .select-result dt{font-weight:bold}
        .select-no{color:#999}
        .select .select-result a{padding-right:20px;background:#2682FF;}
        .select .select-result a:hover{background-position:right -15px}
    </style>
</head>

<body class="listBody">
<div class="qbdms-list">
    <div class="layui-table-view-body " style="height: 100%;position: relative">
        <div class="qbdms-title">
            <div class="leftCon">质量知识</div>
            <div class="rightCon">
<!--                <@f.a alias="zlzsxzan" event="add" css="layui-btn layui-btn-sm fillBtn" >-->
<!--                <span class="layui-btn layui-btn-sm add" style="margin-bottom: 0" qbdms-event="add">新增</span>-->
<!--                <span>新增</span>-->
<!--              </@f.a>-->
                <#if isadd=true>
                <span class="layui-btn layui-btn-sm fillBtn" style="margin-bottom: 0" qbdms-event="add">新增</span>
               </#if>
                <div style="float:left;position: relative">
                    <input name="content" id="content" type="text" class="layui-input" placeholder="请输入" style="width:232px " />
                    <i class="layui-icon layui-icon-search" qbdms-event="selCon"></i>
                </div>
               </div>


        </div>

        <div class="qbdms-list-content">
            <div id="left-tree" class="left-tree"></div>
            <div class="right-list layui-form" id="right-list">

                <div class="qbdms-noData">
                    <img src="${ctx}/qbdmsStatic/images/no.png" alt="">
                    <div>暂无数据</div>
                </div>


                <div class="operationButton">
<!--                    <@f.a alias="xfan_zlzs1,xfan_zlzs2" event="issueBut" css="issueBut" >-->
<!--                    <span>下发</span>-->
<!--                    </@f.a>-->
<!--                    <@f.a alias="zlzsscan" event="delList" css="delList" >-->
<!--                    <span>删除</span>-->
<!--                    </@f.a>-->
                    <#if isadd =="true">
                    <input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose" class="checkbox-all">
                    <span class="delList" qbdms-event="delList">删除</span>
                    </#if>
<!--                    <span style="margin-left: 20px" class="issueBut" qbdms-event="issueBut">下发</span>-->
<!--                    <span class="delList" qbdms-event="delList">删除</span>-->
                </div>
            <div id="main" style="display: none">
                <div class="demo">
                    <ul class="select">
                        <li class="select-list">
                            <dl id="select1">
                                <dt>所属年度：</dt>
                                <dd class="select-all selected"><a href="#">不限</a></dd>
                            </dl>
                        </li>
                        <li class="select-list">
                            <dl id="select2">
                                <dt>发布人：</dt>
                                <dd class="select-all selected"><a href="#">不限</a></dd>
                            </dl>
                        </li>
                        <li class="select-list">
                            <dl id="select3">
                                <dt>密级：</dt>
                                <dd class="select-all selected"><a href="#">不限</a></dd>
                            </dl>
                        </li>
                        <li class="select-list">
                            <dl id="select4">
                                <dt>发布部门：</dt>
                                <dd class="select-all selected"><a href="#">不限</a></dd>

                            </dl>
                        </li>
                        <li class="select-result">
                            <dl>
                                <dt>已选条件：</dt>
                                <dd class="select-no">暂时没有选择过滤条件</dd>
                            </dl>
                        </li>
                    </ul>
                </div>
            </div>

            <div id="list">

                </div>

            </div>
</div>
        <div id="qbdmspage">

        </div>
    </div>
</div>
<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'setter', 'form', 'common','jquery','layer','qbdmsTree','laypage','publicMethods'], function () {
        var setter = layui.setter;
        var form = layui.form;
        var common = layui.common;
        var $ = layui.jquery;
        var layer = layui.layer;
        var tree=layui.qbdmsTree;
        var laypage = layui.laypage;
        var publicMethods = layui.publicMethods;
        var dicId;
        getDicListPage(0)
        function getDicListPage(page){
            //字典
            $.ajax({
                url: serverPath.qbdmsPath + "/qbdms/wQbdQualityKnow/getKnowDic",
                type: "post",
                // data: {id: id},
                dataType: 'json',
                success: function (data) {
                    var data=data.dicList;
                    tree.render({
                        elem: '#left-tree'
                        ,data: data
                        ,accordion:true
                        ,onlyIconControl: true
                        ,click: function(obj){
                            dicId=obj.data.id;
                            query(dicId,1);
                            $(".selected").removeClass("selected");
                            $(".select-all").addClass("selected");
                            $(".select-no").css("display","block");
                            $("#selectA").remove();
                            $("#selectB").remove();
                            $("#selectC").remove();
                            $("#selectD").remove();
                            $("#main").css("display","block")
                            $(".select-no").css("display","block");


                        }
                    });
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            })
        }



        form.on('checkbox(allChoose)', function(data){
            var child = $(data.elem).parents('#right-list').find('.caller-item input[type="checkbox"]');
            child.each(function(index, item){
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });


        /**
         * 动态拼接条件
         *
         *
         */
        var listyear=eval('${listYear}');
        var yearHtml=""
        for(var index in listyear){
            var year= listyear[index];
            yearHtml+="<dd><a   href=\"#\">"+year+" </a></dd>";

        }
        $("#select1").append(yearHtml);

        var sysUsers=eval('${sysUsers}');
        var userHtml="";
        for(var index in sysUsers){
            var account= sysUsers[index].account;
            var fullName=sysUsers[index].fullName;
            userHtml+="<dd><a  account="+account+" href=\"#\">"+fullName+" </a></dd>";

        }
        $("#select2").append(userHtml);


        var mj=eval('${mj}');
        var mjHtml="";
        for(var index in mj){
            var itemName= mj[index].itemName;
            var itemValue=mj[index].itemValue;
            mjHtml+="<dd><a  itemValue="+itemValue+" href=\"#\">"+itemName+" </a></dd>";

        }
        $("#select3").append(mjHtml);


        var sysOrgList=eval('${sysOrgList}');
        var sysOrgListHtml="";
        for(var index in sysOrgList){
            var orgName= sysOrgList[index].orgName;
            var orgId=sysOrgList[index].orgId;
            sysOrgListHtml+="<dd><a  orgId="+orgId+" href=\"#\">"+orgName+" </a></dd>";

        }
        $("#select4").append(sysOrgListHtml);

        var userId="${currentUserId}";
        function dataShow(data){
            var htmlCon='';
            layui.each(data,function (i,item) {
                var src=item.enclosureFileName;
                var reg = RegExp(/.pdf/);
                if(src.match(reg)){
                       src="${ctx}/qbdmsStatic/images/pdf.png"
                }
                var regword=RegExp(/.doc/);
                var regword1=RegExp(/.docx/);
                if (src.match(regword)||src.match(regword1))
                {
                    src="${ctx}/qbdmsStatic/images/word.png"
                }
                var regexcel=RegExp(/.xls/);
                var regexcel1=RegExp(/.xlsx/);
                if (src.match(regexcel)||src.match(regexcel1))
                {
                    src="${ctx}/qbdmsStatic/images/excel.png"
                }
                var htmlsc='';
                // if(item.collectionStatus=="收藏"){
                //     htmlsc='<i class="layui-icon layui-icon-star iconcollection" qbdms-event="iconcollection" id="'+item.id+'" value="1"></i><span qbdms-event="collection" id="'+item.id+'" value="1" class="collections">收藏</span>';
                // }else{
                //     htmlsc='<i class="layui-icon layui-icon-star-fill iconcollection" qbdms-event="iconcollection" style="color: #2682ff" id="'+item.id+'" value="0"></i><span qbdms-event="collection" class="collections" id="'+item.id+'" value="0">取消收藏</span>';
                // }
                var html_edit_delete='';
                if(item.edit==true){
                    html_edit_delete=  '<span qbdms-event="edit" id="'+item.id+'"><i class="layui-icon layui-icon-edit"></i>修改</span>' +
                                       '<span qbdms-event="thisDel" id="'+item.id+'"><i class="layui-icon layui-icon-close" ></i>删除</span>'
                }
                htmlCon=htmlCon+'<div class="caller-item"><input type="checkbox" name="" lay-skin="primary" id="'+item.id+'" > <img src="'+src+'" alt=""> <div class="caller-main"> <p title="'+item.knowledgeName+'" class="main-tit"  id="'+item.id+'" qbdms-event="particulars">'+item.knowledgeName+'</p>'+
                    '<p class="detailed">'+item.enclosureContent+'</p>'+
                    '<div class="main-fun"> <div class="leftCon"> <span class="classification">密级:'+item.secret+'</span>'+
                    '<span class="nameInfo">'+item.fillman+'</span> <span class="timeInfo">发布于 '+publicMethods.timeData(item.createTime)+' </span> </div> <div class="rightCon">'+
                    '<span qbdms-event="downloadFile" fileId="'+item.fileId+'" ><i class="layui-icon layui-icon-link" style="font-size: 12px"></i>下载文件</span>'+
                     html_edit_delete+
                     htmlsc+
                    ' </div> </div> </div> </div>'
            });
            return  htmlCon;
        }

        //刚进入list刷新
        query();
        function query (dicId,page,limit){
            var year;
            var user;
            var mj;
            var dept;
            $(".select-result .selected").each(function (index,element) {
                var id= $(this).attr('id');
                if (id=='selectA'){
                     year= $(this).text();
                }
                if (id=='selectB'){
                     // user= $(this).text();
                    user=  $(this).find('a').attr('account');
                }
                if (id=='selectC'){
                     // mj=  $(this).text();
                    console.log($(this));
                    console.log($(this).find('a').attr('itemvalue'));
                    mj=  $(this).find('a').attr('itemvalue');
                }
                if (id=='selectD'){
                     // dept=  $(this).text();
                    dept=  $(this).find('a').attr('orgid');
                }
            });



            var content=$("#content").val();
            var data={
                content:content,
                dicId:dicId,
                page: page,
                year:year,
                fillmanaccount:user,
                filldeptid:dept,
                mj:mj,
                limit:limit
            }
            $('#list').html("");
            $(".qbdms-noData").css('display','none');
            $.ajax({
                url: serverPath.qbdmsPath + "/qbdms/wQbdQualityKnow/list",
                type: "post",
                data: data,
                dataType: 'json',
                success: function (data) {
                    var count=data.count;
                    var data =data.data;
                    if(count==0){
                        $(".qbdms-noData").css('display','block');
                        return ;
                    }
                    var list=  dataShow(data)
                    $("#list").append(list);
                    laypage.render({
                        elem: 'qbdmspage'
                        ,count: count
                        ,curr:page
                        ,limit:limit
                        ,groups:2
                        ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                        ,jump: function(obj,first){
                            //obj包含了当前分页的所有参数，比如：
                            // console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                            // console.log(obj.limit); //得到每页显示的条数
                            var limit=obj.limit;
                            var page=obj.curr
                            //首次不执行
                            if(!first){
                                //do something
                                if(dicId!=""){
                                    query(dicId,page,limit)
                                }else{
                                    query("",page,limit)
                                }

                            }
                        }
                    });
                    form.render();
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                }
            })
        }


        var events={
            //新增
            add:function () {
                window.location.href = serverPath.qbdmsPath + "/qbdms/wQbdQualityKnow/view/add";
            },
            //详情
            particulars:function () {
                var obj=this;
                var id=$(obj).attr("id");
                window.location.href = serverPath.qbdmsPath + "/qbdms/wQbdQualityKnow/view/particulars?id="+id;
            },
            //下载文件
            downloadFile:function () {
                var obj=this;
                var fileId=$(obj).attr("fileId");
                window.location.href =  "${ctx}"+setter.extendLinkPath + "attachFile/download?fileId=" + fileId;
                },
            //修改
            edit:function () {
                var obj=this;
                var id=$(obj).attr("id");
                window.location.href =  serverPath.qbdmsPath + "/qbdms/wQbdQualityKnow/view/add?id="+id;
                },
            //删除 只能删除当前行
            thisDel:function(){
                var obj=this;
                var id=$(obj).attr("id");
                delFun(id);
            },
            //收藏
            collection:function () {
                var obj=this;
                var id=$(obj).attr("id");
                var status=$(obj).attr("value")
                sc(id,status);
                var domIconColl=$(this).parent().find('.iconcollection');
                events.collectionPub($(this),domIconColl)
            },
            iconcollection:function(){
                var obj=this;
                var id=$(obj).attr("id");
                var status=$(obj).attr("value")
                sc(id,status);
                var domColl=$(this).parent().find('.collections');
                events.collectionPub(domColl,$(this))
            },
            collectionPub:function(dom,icon){
                if(dom.attr('value')==='1'){
                    dom.attr('value','0');
                    dom.html('取消收藏');
                    icon.addClass('layui-icon-star-fill').removeClass('layui-icon-star');
                }else {
                    dom.attr('value','1');
                    dom.html('收藏');
                    icon.addClass('layui-icon-star').removeClass('layui-icon-star-fill');
                }
            },
            //搜索
            selCon:function(){
                query()
            },
            //批量删除
            delList:function () {
                var array = "";
                var ischecked=$(this).parents('#right-list').find('.caller-item input[type="checkbox"]:checked');
                if(ischecked.length>0){
                    ischecked.each(function(index,item) {
                        var id=$(item).attr('id')
                            array+=id+",";
                    });
                    delFun(array);
                }else{
                    layer.alert(publicMethods.confirmStyle('请选择一条数据'),{title: false,skin: 'confirm-class'})
                }
            },
            //下发
            issueBut:function () {
                var array = "";
                var ischecked=$(this).parents('#right-list').find('.caller-item input[type="checkbox"]:checked');
                if(ischecked.length>0){
                    ischecked.each(function(index,item) {
                        console.log($(item).attr('id'))
                        var id=$(item).attr('id')
                        array+=id+",";
                    });
                    xf(array);
                }else{
                    layer.alert(publicMethods.confirmStyle('请选择一条数据'),{title: false,skin: 'confirm-class'})
                }
            }
        };

        //点击事件
        $('body').on('click', '*[qbdms-event]', function(){
            var othis = $(this) ,
            attrEvent = othis.attr('qbdms-event');
            events[attrEvent] && events[attrEvent].call(this, othis);

        });
        //点击事件
        $('body').on('click', '*[lay-event]', function(){
            var othis = $(this) ,
                attrEvent = othis.attr('lay-event');
            events[attrEvent] && events[attrEvent].call(this, othis);
        });

        //删除
        function delFun(id) {
            if (id == ""||typeof id == "undefined") {
                layer.alert(publicMethods.confirmStyle('请先选择一行数据!'),{title: false,skin: 'confirm-class'});
            } else {
                layer.confirm(publicMethods.confirmStyle('确定删除当前数据吗?'),{title: false,skin: 'confirm-class'}, function (index) {
                    layer.close(index);
                    $.ajax({
                        url: serverPath.qbdmsPath + "/qbdms/wQbdQualityKnow/del",
                        type: "post",
                        data: {id:id},
                        dataType: 'json',
                        success: function (data) {
                            layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                            //执行重载
                            query();

                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                            //执行重载
                            query();
                        }
                    })
                })
            }
        }

        /**
         *
         * 下发
         * @param id
         */
        function xf(id) {
            var data={
                id:id,
            }
            if (id == ""||typeof id == "undefined") {
                layer.alert(publicMethods.confirmStyle('请先选择一行数据!'),{title: false,skin: 'confirm-class'});
            } else {
                layer.confirm(publicMethods.confirmStyle('确定下发当前数据吗?'),{title: false,skin: 'confirm-class'}, function (index) {
                    layer.close(index);
                    $.ajax({
                        url: serverPath.qbdmsPath + "/qbdms/wQbdQualityKnow/xf",
                        type: "post",
                        data: data,
                        dataType: 'json',
                        success: function (data) {
                            layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                            //执行重载
                            query();
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                            //执行重载
                            query();
                        }
                    })
                })
            }
        }

        /**
         *  收藏
         * @param id
         * @param status
         */
        function sc(id,status) {
            if (id == ""||typeof id == "undefined") {
                layer.alert(publicMethods.confirmStyle('请先选择一行数据!'),{title: false,skin: 'confirm-class'});
            } else {
                $.ajax({
                    url: serverPath.qbdmsPath + "/qbdms/wQbdQualityKnow/sc",
                    type: "post",
                    data: {qualityknowledgeid:id, status:status},
                    dataType: 'json',
                    success: function (data) {
                        // layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});

                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                    }
                })
            }
        }

//多条件查询
        $(document).ready(function(){

            $("#select1 dd").click(function () {
                $(this).addClass("selected").siblings().removeClass("selected");
                if ($(this).hasClass("select-all")) {
                    $("#selectA").remove();
                } else {
                    var copyThisA = $(this).clone();
                    if ($("#selectA").length > 0) {
                        $("#selectA a").html($(this).text());
                    } else {
                        $(".select-result dl").append(copyThisA.attr("id", "selectA"));
                    }
                }
                query(dicId,1);
            });

            $("#select2 dd").click(function () {
                $(this).addClass("selected").siblings().removeClass("selected");
                if ($(this).hasClass("select-all")) {
                    $("#selectB").remove();
                } else {
                    var copyThisB = $(this).clone();
                    if ($("#selectB").length > 0) {
                        $("#selectB").remove();
                        $(".select-result dl").append(copyThisB.attr("id", "selectB"));
                    } else {
                        $(".select-result dl").append(copyThisB.attr("id", "selectB"));
                    }
                }
                query(dicId,1);

            });

            $("#select3 dd").click(function () {
                $(this).addClass("selected").siblings().removeClass("selected");
                if ($(this).hasClass("select-all")) {
                    $("#selectC").remove();
                } else {
                    var copyThisC = $(this).clone();
                    console.log($(this))
                    if ($("#selectC").length > 0) {
                        $("#selectC").remove();
                        $(".select-result dl").append(copyThisC.attr("id", "selectC"));
                    } else {
                        $(".select-result dl").append(copyThisC.attr("id", "selectC"));

                    }
                }
                query(dicId,1);
            });

            $("#select4 dd").click(function () {
                $(this).addClass("selected").siblings().removeClass("selected");
                if ($(this).hasClass("select-all")) {
                    $("#selectD").remove();
                } else {
                    var copyThisC = $(this).clone();
                    if ($("#selectD").length > 0) {
                        $("#selectD").remove();
                        // $("#selectD a").html($(this).text());
                        $(".select-result dl").append(copyThisC.attr("id", "selectD"));

                    } else {
                        $(".select-result dl").append(copyThisC.attr("id", "selectD"));
                    }
                }
                query(dicId,1);
            });
            $(".select").on("click",'dd', function () {
                if ($(".select-result dd").length > 1) {
                    $(".select-no").hide();
                } else {
                    $(".select-no").show();
                }
            });


        });

        
    });
</script>
</body>
</html>